package com.lovingtour.manager.merchant.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.lovingtour.manager.R;
import com.lovingtour.manager.entity.OrderItemEntity;
import com.lovingtour.manager.util.ApplicationUtils;

public class MerchantOderStarAppraiseAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<OrderItemEntity> dataSources;
    private LayoutInflater inflater;
	public MerchantOderStarAppraiseAdapter(Context context,
			ArrayList<OrderItemEntity> dataSources) {
		
		setDataSources(dataSources);
		inflater = LayoutInflater.from(context);
		this.mContext = context;
	}
	
	public void setDataSources(ArrayList<OrderItemEntity> dataSources){
		if (dataSources!=null) {
			this.dataSources = dataSources;
		}else {
			this.dataSources = new ArrayList<OrderItemEntity>();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dataSources.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return dataSources.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.merchant_starappraise_item, parent, false);
			holder = new ViewHolder();
			holder.tv_commenttime = (TextView) convertView.findViewById(R.id.tv_commenttime);
			holder.tv_downordertime = (TextView) convertView.findViewById(R.id.tv_ordertime);
			holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
			holder.tv_ordernum = (TextView) convertView.findViewById(R.id.tv_ordernum);
			holder.tv_phonenumber = (TextView) convertView.findViewById(R.id.tv_phone);
			holder.tv_servicetype = (TextView) convertView.findViewById(R.id.tv_servicename);
			holder.tv_usercomment = (TextView) convertView.findViewById(R.id.tv_usercomment);
			holder.rb_starappraise = (RatingBar) convertView.findViewById(R.id.rb_starappraise);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		OrderItemEntity entity = dataSources.get(position);
		
		holder.rb_starappraise.setRating(entity.getStar_appraise());
		holder.tv_commenttime.setText(ApplicationUtils.formatDate(entity.getCommenttiem()));
		holder.tv_downordertime.setText(entity.getDownOrderTime());
		holder.tv_name.setText(entity.getName());
		holder.tv_ordernum.setText(entity.getOrderNumber());
		holder.tv_phonenumber.setText(entity.getTelNumber());
		holder.tv_servicetype.setText(entity.getServiceType());
		holder.tv_usercomment.setText(entity.getUserComment());
		
		return convertView;
	}
	
	class ViewHolder{
		TextView tv_name;
		TextView tv_phonenumber;
		TextView tv_ordernum;
		TextView tv_downordertime;
		TextView tv_usercomment;
		TextView tv_servicetype;
		TextView tv_commenttime;
		RatingBar rb_starappraise;
	}

}
